package com.amos.muexamclient.sys.controller;

import com.amos.bean.Result;
import com.amos.muexamclient.sys.service.SysRoleService;
import com.amos.muexamclient.sys.service.dto.SysRoleDTO;
import com.amos.muexamcore.core.BasePageController;
import com.amos.muexamcore.core.BasePageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Copyright © 2018 五月工作室. All rights reserved.
 *
 * @Package com.amos.muexamclient.sys.controller
 * @ClassName SysRoleController
 * @Description TODO
 * @Author Amos
 * @Modifier
 * @Date 2020-03-24 14:35:56
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/sys/role")
public class SysRoleController extends BasePageController<SysRoleDTO> {
    @Autowired
    private SysRoleService sysRoleService;

    @Override
    public BasePageService<SysRoleDTO> getPageService() {
        return sysRoleService;
    }


    @PutMapping("/data-scope")
    public Result dataScope(@RequestBody SysRoleDTO role) {
        this.sysRoleService.checkRoleAllowed(role);
        return Result.success(sysRoleService.authDataScope(role));
    }

    @PutMapping("/change-status")
    public Result changeStatus(@RequestBody SysRoleDTO role) {
        this.sysRoleService.checkRoleAllowed(role);
        return Result.success(this.sysRoleService.save(role));
    }

    @DeleteMapping("/{roleIds}")
    public Result remove(@PathVariable String[] roleIds) {
        return Result.success(sysRoleService.deleteRoleByIds(roleIds));
    }

    @GetMapping("/optionselect")
    public Result opetionSelect() {
        return Result.success(sysRoleService.optionSelect());
    }
}
